<template>
    <div id="mainpage">
        <el-row :gutter="10" style="margin-top:10px;">
            <el-col >
                <div class="grid-content bg-purple">
                    <el-card class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-size: 20px;">我的收藏</span>
                        </div>

                        <template>
                            <el-table :data="test" style="width: 100%" >
                                <el-table-column prop="title" label="标题"  width="450">
                                    <template slot-scope="scope">
                                        <a @click="turnToArticle(scope.row['articleID'])" target="_blank" class="buttonText">{{ scope.row.title }}</a>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="adminName" label="作者" width="300"></el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="a">
                                        <el-button size="mini" type="danger" @click="del(a.$index)">删除</el-button>
                                    </template>
                                </el-table-column>
                                <el-divider></el-divider>
                            </el-table>
                        </template>

                    </el-card>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import axios from 'axios'

    export default {

        created(){
            this.request({
                url:'/collection/'+window.localStorage['username']
            }).then(res=>{
                this.test = res.data;
                //console.log(this.test);
            }).catch(err=>{
                console.log(err);
            });
        },
        data() {
            return {
                test: [
                    {
                        adminName:'',
                        articleId: '',
                        title:''
                    }
                ]
            }
        },
        methods:{
            del(index) {
                // console.log(index);
                console.log(this.test[index]);
                let url = 'http://localhost:8080/delCollection/'+window.localStorage['username']+'/'+this.test[index]['articleID'];
                // axios.post(url, this.test[index]).then(
                //     res=>{
                //         alert("移除成功！");
                //         location.reload(true);
                //         console.log(res.data);
                //     }).catch(err=>{
                //         console.log(err);
                //     }
                // )
                this.request({
                    url:url
                }).then(res=>{
                    this.$message("移除成功！");
                    location.reload(true);
                })
            },
            // render 事件
            renderHeader (h,{column}) { // h即为cerateElement的简写，具体可看vue官方文档
                return h(
                    'div',
                    [
                        h('span', column.label),
                        h('i', {
                            class:'el-icon-location',
                            style:'color:#409eff;margin-left:5px;'
                        })
                    ],
                );
            },
            turnToArticle(articleId){
                this.$router.push({
                    path:'/arcontent',
                    query:{
                        articleID:articleId
                    }}).catch(error=>error);
            }
        },
    }
</script>

<style lang="scss" scoped>
    #mainpage{
        width: 900px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 100px;
        margin-top: 49px;
    }
    .btn-auto{
        width: 100%;
        margin-top: 12px;
    }
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
    a{
        text-decoration: none;
        white-space: nowrap;
    }
    li{
        list-style: none;
        width: 200px;
    }

    //卡片样式
    .text {
        font-size: 14px;
    }

    .item {
        margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }

    .box-card {
        width: 99.5%;
    }
    //文本样式区
    .name-role {
        font-size: 16px;
        padding: 5px;
        text-align:center;
    }
    .sender{
        text-align:center;
    }
    .registe-info{
        text-align: center;
        padding-top:10px;
    }
    .personal-relation {
        font-size: 16px;
        padding: 0px 5px 15px;
        margin-right: 1px;
        width: 100%
    }

    .relation-item {
        padding: 12px;
    }
    .dialog-footer{
        padding-top:10px ;
        padding-left: 10%;
    }
    //布局样式区
    .el-row {
        margin-bottom: 20px;
        &:last-child {
            margin-bottom: 0;
        }
    }
    .el-col {
        border-radius: 4px;
    }
    .bg-purple-dark {
        background: #99a9bf;
    }
    .bg-purple {
        background: #d3dce6;
    }
    .bg-purple-light {
        background: #e5e9f2;
    }
    .grid-content {
        border-radius: 4px;
        min-height: 36px;
        /*position: relative;*/
    }
    .row-bg {
        padding: 10px 0;
        background-color: #f9fafc;
    }
    .el-input{
        width: 400px;
        float: left;
    }
</style>
